-
Notifications
You must be signed in to change notification settings - Fork 7.6k
rtio: add helper function rtio_read_transaction()
#91775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
240bd24
to
d253799
Compare
Is this PR matching your expectation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense, especially as there's already a need in some st drivers. Having it here means we can always update it with a grep and refactor if needed.
+1 from me once the function params are sorted out
d253799
to
d644b5c
Compare
I rebased just to have #91664 included. Still, I have some doubts on this point: |
Try it and see, what I've seen gcc do now is intelligently generate symbols for these functions when they don't meet the inline criteria seemingly, and otherwise inline them. So, I believe (and please tell me I'm wrong if so!) that the compiler inline heuristics are deciding what to inline and when rather than explicitly forcing a function call or always inlining (ALWAYS_INLINE isn't used here). In theory static inline + LTO should be smart and generate symbols per translation unit based on the inlining heuristics, then de-duplicate across the program when linking. At least that is the intent here, but C is weird with this stuff so if that's not the case then I think you are correct that this should probably be a real symbol and function call and all of that. Makes me wonder if we should explore a unity build of zephyr at some point to avoid a lot of the oddities around translation units, inlines, and link time optimizations... but that would probably be very difficult. https://en.wikipedia.org/wiki/Unity_build |
Exploring symbols and assembly code with objdump it seems to me that gcc has generated a routine indeed:
Called in multiple places:
So it seems correct. Thanks for explanation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just dropping a drive-by comment (I can take a look once I'm back at the office next week, unless it's merged before):
I think we'll want to come back later and refactor this when we do introduce the regmap APIs.
Otherwise, I agree this helper is used in many places and it's useful.
include/zephyr/rtio/rtio.h
Outdated
static inline bool rtio_is_spi(rtio_bus_type bus_type) | ||
{ | ||
return (bus_type == BUS_SPI); | ||
} | ||
|
||
static inline bool rtio_is_i2c(rtio_bus_type bus_type) | ||
{ | ||
return (bus_type == BUS_I2C); | ||
} | ||
|
||
static inline bool rtio_is_i3c(rtio_bus_type bus_type) | ||
{ | ||
return (bus_type == BUS_I3C); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add doxygen comments ; also, mention all these new API in release notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but these are meant to be only used internally here. But I can make them as APIs in fact. Good
include/zephyr/rtio/rtio.h
Outdated
* @brief A structure to describe a list of not-consecutive memory chunks | ||
* for RTIO operations. | ||
*/ | ||
struct rtio_reg_buf { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider moving these additions to a separate header file (e.g: include/zephyr/rtio/regmap.h
perhaps?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean only this one, or ALL the inline additions as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll move ALL stuff in regmap.h
include/zephyr/rtio/rtio.h
Outdated
* @param r RTIO context | ||
* @param rtio_callback_t callback routine at the end of op | ||
*/ | ||
static inline void rtio_read_transaction(struct rtio *r, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since "RTIO Transaction" is an already defined term, I'd suggest naming this something else that better reflects the fact that we're doing multiple register reads (chained write-read transactions). For instance:
static inline void rtio_read_transaction(struct rtio *r, | |
static inline void rtio_read_regs_async(struct rtio *r, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems a good name
include/zephyr/rtio/rtio.h
Outdated
} | ||
|
||
if (rtio_is_spi(bus_type)) { | ||
regs[i] |= 0x80; /* mark the SPI read transaction */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should be configurable: there are some drivers that have this inverted (as in: 1 when writing, 0 when reading).
Here's one in-tree example:
zephyr/drivers/sensor/pixart/pat9136/pat9136_reg.h
Lines 11 to 12 in 4ec4351
#define REG_SPI_READ_BIT 0 | |
#define REG_SPI_WRITE_BIT BIT(7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Yes, I remember now that you mentioned it during the WG call, but at the end I forgot it. So, the best thing to do is that the driver would raise the proper bit in regs_list[].reg_addr
(regs_list is the second argument)
@avisconti please address the issues raised by @kartben and @ubieda so we can merge this for 4.2 |
Sorry, yesterday I was in vacation. I'll do it right now |
d644b5c
to
9d5201f
Compare
I included all suggestions from @ubieda and @kartben review. I appreciated your review guys. So sorry I couldn't work on it Friday |
Add a helper function that constructs a rtio SQE chain with the purpose to perform a bus read operation on a list of registers. Usage: uint8_t regs_list[] = { reg_addr1, reg_addr2. ... } struct rtio_reg_buf rbuf[] = {{mem_addr_1, mem_len_1}, {mem_addr_2, mem_len_2}, ... }; rtio_read_transaction(dev, regs_list, ARRAY_SIZE(regs_list), BUS_SPI, rbuf, sqe, iodev, rtio, op_cb); Signed-off-by: Armando Visconti <armando.visconti@st.com>
9d5201f
to
6b38cbe
Compare
|
Add a helper function that constructs a rtio SQE chain with the purpose to perform a bus read operation on a list of registers.
Tested with lsm6dsv16x sensor:
I2C bus: using nucleo_h503rb board + x_nucleo_iks4a1 shield
SPI bus: using sensortile_box_pro
(note that to test with I2C I had to use #91664)
Helper usage:
Points to be discussed: